#include<bits/stdc++.h>
#define int long long
using namespace std;
inline int read(){
	int x=0;bool f=0;char ch=getchar();
	while(ch<'0'||ch>'9')f^=(ch=='-'),ch=getchar();
	while('0'<=ch&&ch<='9')x=(x<<1)+(x<<3)+(ch^48),ch=getchar();
	return f?-x:x;
}
const int Maxn=1e5+5,mod=998244353,base=1313113;
int n,a[Maxn];
vector<int>b;
int ans=0;
unordered_map<int,int>vis;
void dfs(int x){
	if(x==n+1){
		int res=1;
		int ha=0;
		for(int i=1;i<=n;i++)ha=ha*base+b[i];
		if(vis[ha])return;
		vis[ha]=1;
		for(int i=1;i<=n;i++)res=res*b[i]%mod;
		ans=(ans+res)%mod;
		return;
	}
	for(int i=0;i<=a[x];i++){
		b[x]-=i;
		b[x%n+1]+=i;
		dfs(x+1);
		b[x]+=i;
		b[x%n+1]-=i;
	}
}
signed main(){
	freopen("trade.in","r",stdin);
	freopen("trade.out","w",stdout);
	int ok=1;b.push_back(0);
	n=read();for(int i=1;i<=n;i++)a[i]=read(),ok&=(a[i]<=1),b.push_back(a[i]);
	if(ok){
		int cnt=0;
		for(int i=1;i<=n;i++)cnt+=a[i];
		if(cnt==n)puts("1");
		else puts("0");
		return 0;
	}
	dfs(1);
	printf("%lld\n",ans);
	return 0;
}
/*
5
11 12 5 9 6
556415460
*/
